package servlet.Course;

import dao.impl.CourseDaoImpl;
import dao.impl.StudentIDaoImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet({"/course/Delete"})
public class CourseDelete extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");//请求编码
        resp.setContentType("text/html;charset=utf-8");//响应编码
        String con = req.getParameter("cno");
        CourseDaoImpl dao = new CourseDaoImpl();
        int row = dao.deleteCourse(con);
        HttpSession session = req.getSession();
        if (row > 0) {
            req.getRequestDispatcher("/courseAllServlet").forward(req,resp);
        }else{
            session.setAttribute("msg","内部错误，稍后重试！"); //存储到缓存
            resp.sendRedirect("/err/error.jsp");
        }
    }
}
